#include "gamedata.h"

QHash<QString, QPixmap*> GameData::tiletextures;
QHash<QString, QPixmap*> GameData::shiptextures;
QHash<QString, QPixmap*> GameData::windowtextures;

GameData::GameData()
{
}

void GameData::importTextures() {
    // import the watertile images
    QDir tileDir ("images/tiles");
    QFileInfoList tileFiles = tileDir.entryInfoList();

    for (size_t i = 0; i < tileFiles.size(); ++i) {
        QFileInfo file = tileFiles.at(i);
        if (file.isFile() && file.fileName().contains(".png")) {
            tiletextures[file.baseName()] = new QPixmap("images/tiles/" + file.fileName());
        }
    }

    // import all ship images
    QDir shipDir ("images/ships");
    QFileInfoList shipFiles = shipDir.entryInfoList();

    for (size_t i = 0; i < shipFiles.size(); ++i) {
        QFileInfo file = shipFiles.at(i);
        if (file.isFile() && file.fileName().contains(".png")) {
            shiptextures[file.baseName()] = new QPixmap("images/ships/" + file.fileName());
        }
    }

    //import window images
    QDir windowDir ("images/window");
    QFileInfoList windowFiles = windowDir.entryInfoList();

    for (size_t i = 0; i < windowFiles.size(); ++i) {
        QFileInfo file = windowFiles.at(i);
        if (file.isFile() && (file.fileName().contains(".png") || file.fileName().contains(".gif"))) {
            windowtextures[file.baseName()] = new QPixmap("images/window/" + file.fileName());
        }
    }

}
